<template>
  <div id="app" class="wrapper wrapper-content animated fadeInRight v-cloak" v-cloak>
    <div class="row">
      <div class="col-md-12">
        <form id="examineTargetDetailForm" method="post" class="form m-t" @submit.prevent="save()"
            accept-charset="UTF-8">
          <input type="hidden" name="id" v-model="item.id"/>
          <input type="hidden" name="token" v-model="item.token"/>
          <input type="hidden" name="newFlag" v-model="newFlag"/>
          <div class="clearfix "></div>
          <div class="col-md-6">
            <div class="form-group clearfix">
              <label class="col-md-8 control-label">考核指标名称：</label>
              <div class="col-md-12">
                <input id="bean-name" name="name" v-model="item.name" class="form-control" type="text"
                    placeholder="请输入考核指标名称" required="" aria-required="true" aria-describedby="bean-name-error"
                    maxlength="55" aria-invalid="true">
                <input id="bean-targetId" name="targetId" v-model="item.targetId" type="hidden" required="">
                <span id="bean-name-error" class="help-block m-b-none" for="bean-name"></span>
              </div>
            </div>

            <div class="form-group clearfix">
              <label class="col-md-8 control-label">考核指标类型：</label>
              <div class="col-md-12">
                <select data-placeholder="选择指标考核类型"
                    id="bean-examineType" name="examineType" class="form-control" required="" aria-required="true"
                    aria-describedby="bean-examineType-error" aria-invalid="true">
                  <option value="">--请选择考核指标类型--</option>
                  <option value="政策制度" :selected="item.examineType == '政策制度'">政策制度</option>
                  <option value="水资源保护" :selected="item.examineType == '水资源保护'">水资源保护</option>
                  <option value="岸线保护和防汛安全" :selected="item.examineType == '岸线保护和防汛安全'">岸线保护和防汛安全</option>
                  <option value="水环境整治" :selected="item.examineType == '水环境整治'">水环境整治</option>
                  <option value="执法监管" :selected="item.examineType == '执法监管'">执法监管</option>
                  <option value="否决条款" :selected="item.examineType == '否决条款'">否决条款</option>
                  <option value="附加分项" :selected="item.examineType == '附加分项'">附加分项</option>
                  <option value="水污染防治" :selected="item.examineType == '水污染防治'">水污染防治</option>
                  <option value="水生态修复" :selected="item.examineType == '水生态修复'">水生态修复</option>
                </select>
                <span id="bean-examineType-error" class="help-block m-b-none" for="bean-examineType"></span>
              </div>
            </div>

            <div class="form-group clearfix">
              <label class="col-md-8 control-label">评价类别：</label>
              <div class="col-md-12">
                <select data-placeholder="选择指价类别"
                    id="bean-scoreType" name="scoreType" class="form-control" required="" aria-required="true"
                    aria-describedby="bean-scoreType-error" aria-invalid="true">
                  <option value="">--请选择价类别--</option>
                  <option value="1" :selected="item.scoreType == 1">自动评分</option>
                  <option value="2" :selected="item.scoreType == 2">人工评分</option>
                </select>
                <span id="bean-scoreType-error" class="help-block m-b-none" for="bean-scoreType"></span>
              </div>
            </div>

            <div class="form-group clearfix">
              <label class="col-md-8 control-label">标准分：</label>
              <div class="col-md-12">
                <input id="bean-normScore" name="normScore" v-model="item.normScore" class="form-control" type="text"
                    placeholder="请输入标准分" required="" aria-required="true" aria-describedby="bean-normScore-error"
                    aria-invalid="true" digits="true">
                <span id="bean-normScore-error" class="help-block m-b-none" for="bean-normScore"></span>
              </div>
            </div>

          </div>
          <div class="col-md-6">

            <div class="form-group clearfix">
              <label class="col-md-8 control-label">考核内容：</label>
              <div class="col-md-12">
                <textarea id="bean-content" name="content" class="form-control" placeholder="请输入考核内容" required=""
                    aria-required="true" aria-describedby="bean-content-error" maxlength="1024"
                    aria-invalid="true">{{item.content}}</textarea>
                <span id="bean-content-error" class="help-block m-b-none" for="bean-content"></span>
              </div>
            </div>
            <div class="form-group clearfix">
              <label class="col-md-8 control-label">考核打分细则：</label>
              <div class="col-md-12">
                <textarea id="bean-gradeDetail" name="gradeDetail" class="form-control" placeholder="请输入考核打分细则"
                    required="" aria-required="true" aria-describedby="bean-gradeDetail-error" maxlength="1024"
                    aria-invalid="true">{{item.gradeDetail}}</textarea>
                <span id="bean-gradeDetail-error" class="help-block m-b-none" for="bean-gradeDetail"></span>
              </div>
            </div>
            <div class="form-group clearfix">
              <label class="col-md-8 control-label">考核项排序号：</label>
              <div class="col-md-12">
                <input id="bean-sequence" name="sequence" v-model="item.sequence" class="form-control" type="text"
                    placeholder="请输入考核项排序号" required="" aria-required="true" aria-describedby="bean-sequence-error"
                    maxlength="32" aria-invalid="true">
                <span id="bean-sequence-error" class="help-block m-b-none" for="bean-sequence"></span>
              </div>
            </div>

            <div class="form-group clearfix">
              <label class="col-md-8 control-label">备注：</label>
              <div class="col-md-12">
                <input id="bean-memo" name="memo" v-model="item.memo" class="form-control" type="text"
                    placeholder="请输入备注" aria-describedby="bean-memo-error" maxlength="255" aria-invalid="true">
                <span id="bean-memo-error" class="help-block m-b-none" for="bean-memo"></span>
              </div>
            </div>

          </div>

          <div class="clearfix "></div>
          <div class="col-12 text-center" style="height: 50px;">
            <div>
              <input class="btn btn-primary" type="submit" value="保存"/> | <a @click="lbox.closeMyBoxLayer()" class="btn btn-danger" href="javascript:">返回</a>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</template>
<script type="text/javascript">
import '@/assets/css/style.css'

import $ from '@/assets/js/jquery-vendor.js'
import 'jquery.cookie'
import axios from 'axios'
import '@/assets/js/validate/validation-vendor.js'

import {apiUtil, axiosContentType, site} from '@/assets/js/boss'

export default {
  data() {
    return {
      item: {},
      newFlag: 0,
      uuidToken: ''
    }
  },
  mounted() {
    let that = window.$vueApp = this;
    that.item.targetId = sessionStorage.getItem(site.examineTarget.info);
    document.getElementsByTagName('body')[0].className = 'fixed-sidebar full-height-layout';
    $('#examineTargetDetailForm').validate();
    that.staff.init(function () {
      that.newFlag = sessionStorage.getItem(site.examineTargetDetail.info);
      if (that.newFlag) that.uuidToken = apiUtil.guid();
      if (apiUtil.existSessionKey(site.examineTargetDetail.info)) {
        that.info();
      }
    });
  },
  methods: {
    info() {
      let that = this;
      axios.get(site.examineTargetDetail.info + sessionStorage.getItem(site.examineTargetDetail.info), {}).then(function (response) {
        const result = response.data;
        if (result.code === 0) {
          that.item = result.data;
        } else {
          alert(result.message);
        }
      });
    },
    save() {
      let that = this;
      if ($('#examineTargetDetailForm').valid()) {
        axios.post(site.examineTargetDetail.save, $('#examineTargetDetailForm').serialize(),
            axiosContentType.xWwwFormUrlencoded).then(function (response) {
          const result = response.data;
          // console.info("获取数据.." + JSON.stringify(result));
          if (result.code === 0) {
            parent.$vueApp.page();
            alert('保存成功!');
            that.lbox.closeMyBoxLayer()
          } else {
            alert(result.message);
          }
        });
      }
    }
  }
}
</script>

